package cn.mumzone.pos.ui.adapter;

import android.content.Context;
import android.widget.TextView;

import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.AppDateUtil;
import cn.mumzone.basic.util.BigDecimalUtil;
import cn.mumzone.basic.util.StringUtils;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.IntegralRecordEntity;
import cn.mumzone.pos.model.TransactionRecordEntity;
import cn.mumzone.pos.util.BillUtil;

/**
 * Created by qiuzhenhuan on 2019/8/1.
 */

public class ADA_IntegralRecord extends CommonAdapter<IntegralRecordEntity> {

    public ADA_IntegralRecord(Context context) {
        super(context);
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.item_integral_record;
    }

    @Override
    protected void convert(ViewHolder holder, IntegralRecordEntity entity, int position) {

        TextView tvDay = holder.getView(R.id.tv_day);
        TextView tvDealType = holder.getView(R.id.tv_deal_type);
        TextView tvIntegral = holder.getView(R.id.tv_integral);
        TextView tvBalance = holder.getView(R.id.tv_integral_balance);
        TextView tvCode = holder.getView(R.id.tv_code);


        tvDay.setText(AppDateUtil.getFriendlyDateTime(entity.getCreateTime(), AppDateUtil.HH_MM_SS, AppDateUtil.YYYY_MM_DD_HH_MM_SS));
        tvDealType.setText(getDealType(entity));

        String integral = String.format("%s%s", getDealTypeIsInCome(entity)
                ? "+" : "-", BigDecimalUtil.getNumber(entity.getIntegral()));
        tvIntegral.setText(integral);
        tvBalance.setText(BigDecimalUtil.getNumber(entity.getEndIntegral()));
        tvCode.setText(StringUtils.get(entity.getOrderCode(), "---"));

    }

    private String getDealType(IntegralRecordEntity entity) {
        switch (entity.getDealType()) {
            case "0":
                return "门店消费积分";
            case "1":
                return "充值积分";
            case "2":
                return "积分抵现";
            case "3":
                return "积分换购";
            case "4":
                return "退货扣减";
            case "5":
                return "退卡扣减";
            case "6":
                return "升级赠送";
            case "7":
                return "完善信息积分";
            case "8":
                return "邀请好友积分";
            case "9":
                return "签到积分";
            case "10":
                return "积分失效";
            case "11":
                return "兑换优惠券";
            case "12":
                return "积分清零";
            default:
                return "";
        }
    }

    private boolean getDealTypeIsInCome(IntegralRecordEntity entity) {
        return "0".equals(entity.getDealType()) || "1".equals(entity.getDealType()) ||
                "6".equals(entity.getDealType()) || "7".equals(entity.getDealType())
                || "8".equals(entity.getDealType()) || "9".equals(entity.getDealType());
    }
}
